#include "Fs.h"
#include "utility/Stream.h"
#include "Utils.h"


#define TEMP_ADDR (8 * 1024 * 1024)
#define TEMP_FILE_ID 100

static uint8_t* currentPos;

int SysOpen(const char *name, int flags, ...)
{
    if (name[0] == '/')
    {
        LoadDataFromDisk(5000, 80, TEMP_ADDR);
        currentPos = (uint8_t*)TEMP_ADDR;
        return TEMP_FILE_ID;
    }
    return -1;
}

int SysRead(int file, char *ptr, int len)
{
    if (file == TEMP_FILE_ID)
    {
        Memcpy(ptr, currentPos, len);
        currentPos+=len;
        return len;
    }
    return -1;
}

int SysWrite(int file, char *ptr, int len)
{
    return -1;
}

int SyslSeek(int file, int ptr, int dir)
{
    if (file==TEMP_FILE_ID)
    {
        currentPos = (uint8_t*)(ptr + TEMP_ADDR);
        return 0;
    }
    return -1;
}

int SysClose(int file)
{
    return 0;
}

